package com.school.basic.controller;

import com.school.basic.entity.StudentInfo;
import com.school.basic.service.StudentInfoService;
import com.school.untils.ResultEntity;
import com.school.untils.ResultUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Api(tags = "学生信息管理")
@RestController
@RequestMapping("/studentInfo")
public class StudentInfoController {
    @Autowired
    StudentInfoService studentInfoService;
    // 查询所有
    @ApiOperation("根据账号和密码查询学生信息")
    @RequestMapping(value = "/findStudentByAccountAndPassword",method = RequestMethod.GET)
    public ResultEntity findStudentByAccountAndPassword(Integer account, String password){
        return ResultUtils.build(studentInfoService.findStudentByAccountAndPassword(account, password));
    }


    // 增加
    @ApiOperation("学生信息增加")
    @RequestMapping(value = "/add",method = RequestMethod.POST)
    public ResultEntity addStudentInfo(@RequestBody StudentInfo studentInfo){
        return  ResultUtils.build(studentInfoService.addStudentInfo(studentInfo));
    }

    // 查询所有
    @ApiOperation("学生信息查询所有")
    @RequestMapping(value = "/findAll",method = RequestMethod.GET)
    public ResultEntity<Object> findAll(){
        return ResultUtils.build(studentInfoService.findAll());
    }

    // 更新
    @ApiOperation("学生信息更新")
    @RequestMapping(value = "/update",method = RequestMethod.POST)
    public ResultEntity updateStudentInfo(@RequestBody StudentInfo studentInfo){
        return ResultUtils.build(studentInfoService.updateStudentInfo(studentInfo));
    }

    // 学生状态变更
    @ApiOperation("学生状态变更")
    @RequestMapping(value = "/updateStatus",method = RequestMethod.POST)
    public void updateStatus(String id, Integer status){
        studentInfoService.updateStatus(id,status);
    }

    // 根据id查看详情
    @ApiOperation("学生信息查看详情")
    @GetMapping("/getDetailsById/{id}")
    public ResultEntity getDetailsById(@PathVariable("id") String id){
        return ResultUtils.build(studentInfoService.getDetailsById(id));
    }

    // 根据id删除
    @ApiOperation("学生信息信息删除")
    @DeleteMapping("/delete/{id}")
    public void deleteStudentInfo(@PathVariable("id") String id){
        studentInfoService.deleteStudentInfo(id);
    }

    // 根据id批量删除
    @ApiOperation("学生信息批量删除")
    @DeleteMapping("/batch")
    public void deleteStudentInfoList(String idList){
        studentInfoService.deleteStudentInfoList(idList);
    }

    // 根据条件分页查询
    @ApiOperation("根据条件分页查询")
    @GetMapping("/specificPage")
    public ResultEntity specificPageQueryStudentInfoList(StudentInfo studentInfo,@RequestParam int page,@RequestParam int size){
        return ResultUtils.build(studentInfoService.specificPageQueryStudentInfoList(studentInfo,page,size));
    }
}
